<?php
class Core_Model_Sessions {
	
	private $expireTime = 300;
	private $loggedIn;
	private $userData;
	
	public $userInfo = array();
	
	public function __construct(){
		
		session_cache_expire($this->expireTime);
		
	}
	
	public function checkUser(array $postVars){
		try {
			//if($this->checkData($postVars) == true){
				return $this->getUserData($postVars);
			//}
			//else {
				//throw new Exception("The system can not find your data!\n");
			//}
		}
		catch(Exception $e){
			echo $e->getMessage();
		}
	}
	
	private function getUserData(array $postVars){
		$userData = new Core_Data_UserData();
		return $userData->getUserData($postVars);
		
	}
	
	private function checkData(array $postVars){
		try {
			if(isset($postVars['name']) && isset($postVars['password'])){
				if((trim($postVars['name']) != "") && (trim($postVars['password']) != "")){
					return true;
				}	
				else {
					//throw new Exception("Username or password can not be empty!\n");
				}
			}
			else {
				//throw new Exception("Men, it's a hacking. Exception has been saved in logs!\n");
			}
		}	
		catch(Exception $e){
			echo $e->getMessage();
		}
	}
	
	private function sessionIsReady(array $sessionInfo){
		
		if(isset($_SESSION['username']) && ($_SESSION['username'] != "GUEST")){
			$this->loggedIn = true;
		}
		else {
			$this->loggedIn = false;
		}
		return $this->loggedIn;
		
	}
}